using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using System.Threading;
using System.IO;

namespace SharepointListMigrator
{
    /// <summary>
    /// This application copies records from sharepoint 2003 lists to sharepoint 2007 lists.
    /// </summary>
    public partial class Migrator : Form
    {

        public Migrator()
        {
            InitializeComponent();
            //allow all certs (because they may not be signed by a trusted provider)
            System.Net.ServicePointManager.CertificatePolicy = new TrustAllCertificatePolicy();

#if DEBUG
            //for debugging work
						txtSource.Text = "http://testbox/Lists/Contacts";
						txtDestination.Text = "http://test";
            txtUserName.Focus();
#endif

        }

        private void btnMigrate_Click(object sender, EventArgs e)
        {
            Cursor currentCursor = Cursor.Current;
            Cursor.Current = Cursors.WaitCursor;

            try
            {

							//first clone the list
							ListCloner cloner = new ListCloner(txtUserName.Text, txtPassword.Text, txtDomain.Text);
							cloner.CloneList(txtSource.Text, txtDestination.Text);

                //To migrate more lists add a new class which extends ListMigratorAlgorithm and add it to the generic list below 
                //in a similar fashion to how NewsListMigratorAlgorithm is added.
                List<ListMigrator> listMigrators = new List<ListMigrator>();
                //listMigrators.Add(new ListMigrator(new NewsListMigratorAlgorithm(), txtUserName.Text, txtPassword.Text, txtDomain.Text));

								//foreach (ListMigrator migrator in listMigrators)
								//{
								//    migrator.MigrateList(txtSource.Text, txtDestination.Text);
								//    MessageBox.Show(string.Format("List '{0}' has been successfully migrated.", migrator.ListName), "List Migration Complete", MessageBoxButtons.OK);
								//}

            }
            catch (System.Web.Services.Protocols.SoapException soapEx)
            {
                MessageBox.Show(soapEx.Message + "\n" + soapEx.Detail.OuterXml, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                Cursor.Current = currentCursor;
            }

        }

       

        

        
       
    }
}